package org.liveboardgames.agricola.control.delegates.action.processor
{
    import org.liveboardgames.agricola.control.events.intern.ActionEvent;
    import org.liveboardgames.agricola.model.enums.BirthStatusEnum;
    import org.liveboardgames.agricola.vo.action.Action;
    import org.liveboardgames.agricola.vo.card.Card;
    import org.liveboardgames.agricola.vo.common.Peep;
    import org.liveboardgames.agricola.vo.player.Player;
    
    public class BirthActionProcessor extends ActionProcessor
    {
        public function BirthActionProcessor(action:Action)
        {
            super(action);
        }
        
        override public function execute():void
        {
            var player:Player = action.target as Player;
            
            // Create a new peep
            var peep:Peep = new Peep();
            peep.status = BirthStatusEnum.NEWBORN;
            player.peeps.addItem(peep);
            
            // The card that holds the peeps
            if (action.link != null && action.link is Card)
            {
                var card:Card = action.link as Card;
                card.addPeep(peep);
            }
            
            // Notify that the action has been completed
            this.dispatchEvent(new ActionEvent(ActionEvent.ACTION_COMPLETE));
        }
    }
}